package com.s1nx.back.dao;

import com.s1nx.back.entity.Book;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface BookDao {
    //获取所有书籍信息
    @Select("SELECT * FROM fb_book")
    List<Book> getAllBooks();

    //根据id获取书籍信息
    @Select("SELECT * FROM fb_book WHERE id = #{id}")
    Book getBookById(int id);

    //根据title查询书籍信息
    @Select("SELECT * FROM fb_book WHERE title = #{title}")
    Book getBookByTitle(String title);

    //根据id删除书籍信息
    @Delete("DELETE FROM fb_book WHERE id = #{id}")
    int deleteBookById(int id);

    //根据id更新书籍信息
    @Update("UPDATE fb_book SET title = #{title}, author = #{author}, price = #{price}, num = #{num}, update_time = #{updateTime} WHERE id = #{id}")
    int updateBookById(Book book);

    //新增书籍信息
    @Insert("INSERT INTO fb_book(title, author, price, num, create_time, update_time) VALUES(#{title}, #{author}, #{price}, #{num}, #{createTime}, #{updateTime})")
    int addBook(Book book);
}
